import type * as Common from './type'
import http from '@/utils/http'

const BASE_URL = '/auth'

/** @desc 账号登录 */
export function loginByAccount(req: Common.AccountLoginReq) {
  return http.post<Common.LoginResp>(`${BASE_URL}/account`, req)
}

/** @desc 手机号登录 */
export function loginByPhone(req: Common.PhoneLoginReq) {
  return http.post<Common.LoginResp>(`${BASE_URL}/phone`, req)
}

/** @desc 三方账号登录 */
export function loginBySocial(source: string, req: any) {
  return http.post<Common.LoginResp>(`/oauth/${source}`, req)
}

/** @desc 三方账号登录授权 */
export function socialAuth(source: string) {
  return http.get<Common.SocialAuthAuthorizeResp>(`/oauth/${source}`)
}

/** @desc 获取微信openid */
export function getWxOpenId(code: string) {
  return http.get<any>(`${BASE_URL}/wx-mp/getOpenId/${code}`)
}

/** @desc 微信一键授权登录 */
export function loginByWxPhone(code: string) {
  return http.post<Common.LoginResp>(`${BASE_URL}/wx-mp/loginByPhoneNumber/${code}`)
}

/** @desc 退出登录 */
export function logout() {
  return http.post(`${BASE_URL}/logout`)
}
